<?php

require_once(TEST_CONFIGURATION_PATH . 'Configuration.php');
require_once(TEST_INTEGRATION_PATH . 'ConnectionFactory.php');

class TestOfConfiguration extends UnitTestCase {
	
	private $cf;
	
	function __construct() {
		$this->cf = new Configuration(new ConnectionFactory());
		
		// Override the Standard Configuration with the Test Configuration
		$this->cf->set('DB_SERVER', TEST_DB_SERVER);
		$this->cf->set('DB_SERVER_USERNAME', TEST_DB_SERVER_USERNAME);
		$this->cf->set('DB_SERVER_PASSWORD', TEST_DB_SERVER_PASSWORD);
		$this->cf->set('DB_DATABASE', TEST_DB_DATABASE);
		$this->cf->set('TABLE_PREFIX', '');
		
		// Reconnect to the test database
		$this->cf->connect();
		
	}

	function testShouldReturnConfigurationValue() {
		$this->assertEqual("Shipping", $this->cf->get("STORE_PRODUCT_TAX_BASIS"));
		$this->assertEqual("false", $this->cf->get("DISPLAY_PRICE_WITH_TAX"));
		$this->assertFalse($this->cf->get("SHOW_PRODUCTS_SOLD_OUT"));
	}

	function testShouldSetCorrectValue() {
		$this->cf->set('DB_SERVER', 'Random Name');
		$this->assertEqual("Random Name", $this->cf->get("DB_SERVER"));
		$this->cf->set('TABLE_ADDRESS_FORMAT', 'Random Table');
		$this->assertEqual("Random Table", $this->cf->get("TABLE_ADDRESS_FORMAT"));
		$this->assertFalse($this->cf->set("INEXISTENT_KEY", "Value"));
	}
	
	/*
	function testShouldbeInCache() {
		$this->cf->get("STORE_PRODUCT_TAX_BASIS");
		$this->cf->get("STORE_PRODUCT_TAX_BASIS");
	}
	*/

	function testShouldThrowException() {
		$this->expectException( new Exception("Configuration value for INEXISTENT_KEY not found") );
		throw new Exception("Configuration value for INEXISTENT_KEY not found");
		$this->cf->get("INEXISTENT_KEY");
	}
	
}
?>
